<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>默认日期选择范围是本月1号到昨日</title>

    <link rel="stylesheet" href="../plugins/layui/css/layui.css">
    <script src="../plugins/layui/layui.js"></script>

</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>日期选择控件</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">左右面板</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input date-item" id="test">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">日期范围</label>
        <div class="layui-input-inline" style="width: 190px;">
            <input type="text" class="layui-input date-item" id="start">
        </div>
        <div class="layui-form-mid">-</div>
        <div class="layui-input-inline" style="width: 190px;">
            <input type="text" class="layui-input date-item" id="stop">
        </div>
    </div>
</form>


<script>
    layui.use(['laydate'],function() {
        var laydate=layui.laydate;
        var d = new Date();
        d.setTime(d.getTime()-24*60*60*1000);
        var max = d.getFullYear()+"-" + (d.getMonth()+1) + "-" + d.getDate();
        var min=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+"1";
        //采用第1种方式 开启range实现默认选择1号到昨日的
        laydate.render({
            elem:'#test',
            range:true,
            min:min,
            max:max
        });
        //采用第2种方式 设定2个日期/时间选择器实现
        /*var s=laydate.render({
            elem:'#start',
            min:min,
            max:max,
            ready:function(date) {
                //s.hint('日期只允许在<br>'+min+' 至 '+max+' 选择');
            }
        });
        var e=laydate.render({
            elem:'#stop',
            min:min,
            max:max,
            ready:function(date) {
                //e.hint('日期只允许在<br>'+min+' 至 '+max+' 选择');
            }
        });*/
        //等同于以下代码
        //同时绑定多个
        lay('.date-item').each(function(){
            var ld=laydate.render({
                elem: this,
                trigger: 'click',
                min:min,
                max:max,
                ready:function(date) {
                    //ld.hint('日期只允许在<br>'+min+' 至 '+max+' 选择');
                }
            });
        });
    });
</script>
</body>
</html>